package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.CustomerView;

public class CustomerViewPresenter extends AbstractPresenter<CustomerView> {
	final String SINGLEITEM = "customerView";
	final String MULTIITEM = "customerViews";
	
	public ArrayList<CustomerView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public CustomerView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public CustomerView createItemFromJSONObject(JSONObject jsonObject){
		CustomerView item = new CustomerView();
		try{
			item.setId(jsonObject.getInt("cId"));
			item.setName(jsonObject.getString("cName"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(CustomerView item){
		try{
			JSONObject json = new JSONObject();
			json.put("cId", item.getId());
			json.put("cName", item.getName());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public CustomerView getEmptyEntity(){
		CustomerView entity = new CustomerView();
		return entity;
	}
}
